package pl.enigmatic.visual.javax.vecmath;

import javax.swing.JPanel;
import javax.vecmath.Matrix4f;

import pl.enigmatic.awt.Frames;
import pl.enigmatic.random.RandomFloat;
import pl.enigmatic.random.RandomInteger;
import pl.enigmatic.test.ControllerFrame;
import pl.enigmatic.test.INamedPanel;
import pl.enigmatic.time.Timer;
import pl.enigmatic.time.TimerTask;
import pl.enigmatic.visual.util.math.MatrixVisualizerBase;


public class Matrix4fVisualizer extends MatrixVisualizerBase<Matrix4f> {

	public static void main(final String[] args) {
		final Matrix4f matrix = new Matrix4f();
		new Timer().schedule(new TimerTask() {

			private final RandomInteger index = new RandomInteger(0, 3);
			private final RandomFloat value = new RandomFloat(-1, 1);

			@Override
			public void run(final double dt) {
				matrix.setElement(index.draw(), index.draw(), value.draw());
			}
		});
		Frames.show(new ControllerFrame(new INamedPanel() {

			@Override
			public JPanel getPanel() {
				return new Matrix4fVisualizer(matrix);
			}

			@Override
			public String getName() {
				return null;
			}
		}));
	}

	/** */
	private static final long serialVersionUID = 1L;

	public Matrix4fVisualizer(final Matrix4f x) {
		super(x);
	}

	public Matrix4fVisualizer(final Object source, final String property) throws Exception {
		super(source, property);
	}

	@Override
	protected int getRows() {
		return 4;
	}

	@Override
	protected int getCols() {
		return 4;
	}

	@Override
	protected double get(final Matrix4f m, final int row, final int col) {
		return m.getElement(row, col);
	}

	@Override
	protected void set(final Matrix4f m, final int row, final int col, final double val) {
		m.setElement(row, col, (float) val);
	}

}
